
const _init = Symbol('_init');
const _count = Symbol('_count');
const _switchAnima = Symbol('_switchAnima');
const _error = Symbol('_error');
export default class UtilsVisualTracking {
    constructor(_options, _that) {
        this.options = _options;
        if (!_options) return this[_error]('no options?');
        this[_init](_that);
    }

    [_count](_target, _npc, _that) {
        let vx = _npc.deltaX - _target.deltaX;
        let vy = _npc.deltaY - _target.deltaY;
        this.options.anima == 'four' ? this[_switchAnima]('four', vx, vy, _that) : this[_switchAnima]('eight', vx, vy, _that);
        let rlen = Math.sqrt(vx * vx + vy * vy);
        return {
            dx: vx / rlen,
            dy: vy / rlen
        };
    }

    [_switchAnima](_type, _vx, _vy, _that) {
        switch (_type) {
            case 'four':
                // console.log(Math.round((((Math.atan2(_vy, _vx) * (180 / Math.PI)) + 180) / 90) + 3) % 4);
                let direction = Math.round((((Math.atan2(_vy, _vx) * (180 / Math.PI)) + 180) / 90) + 3) % 4;
                switch (direction) {
                    case 0:
                        _that[this.options.spriteKey].anims.play(`humanBottomAnima`, true);
                        break;
                    case 1:
                        _that[this.options.spriteKey].anims.play(`humanLeftAnima`, true);
                        break;
                    case 2:
                        _that[this.options.spriteKey].anims.play(`humanTopAnima`, true);
                        break;
                    case 3:
                        _that[this.options.spriteKey].anims.play(`humanRightAnima`, true);
                        break;
                }
                break;
            case 'eight':
                break;
        }
    }

    [_init](_that) {
        switch (this.options.type) {
            case 'monomer':
                this.options.npc.x -= this[_count]({
                    deltaX: this.options.target.x,
                    deltaY: this.options.target.y
                }, {
                    deltaX: this.options.npc.x,
                    deltaY: this.options.npc.y
                }, _that).dx * this.options.speed;
                this.options.npc.y -= this[_count]({
                    deltaX: this.options.target.x,
                    deltaY: this.options.target.y
                }, {
                    deltaX: this.options.npc.x,
                    deltaY: this.options.npc.y
                }, _that).dy * this.options.speed;
                break;
            case 'group':
                break;
        }
    }


    [_error](err) {
        throw err;
    }
}